# -*- coding: utf-8 -*-
import string
import re

change = {}
suflen = {}

ski = ["skiego", "scy", "skich", "skim", "skiemu", "ska", "skiej", "sk?", "skimi"]#, "ski"]
for suffix in ski:
   change[suffix] = 'ski'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
      
cki = ["ckiego", "ccy", "ckich", "ckim", "ckiemu", "cka", "ckiej", "ck?", "ckimi"]#, "cki"]
for suffix in cki:
   change[suffix] = 'cki'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
usz = ["usz@w", "uszowi", "usza", "uszu", "uszom", "uszach", "uszem", "usze", "uszami", "uszowej", "uszowa", "uszowe", "uszowych", "uszowym"]#, "ucz"]
for suffix in usz:
   change[suffix] = 'usz'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
isz = ["iszowi", "isza", "iszu", "iszom", "iszach", "iszem", "isze", "iszami", "iszowa", "iszowej", "iszowe", "iszowych", "iszowym"]
for suffix in isz:
   change[suffix] = 'isz'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
czyk = ["czyk@w", "czykom", "czyka", "czykowi", "czykiem", "czycy", "czykowa" "czykowie", "czykami", "czykowej", "czykowe", "czykowych", "czykowym"] #, 'czyk']
for suffix in czyk:
   change[suffix] = 'czyk'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)

al = ["a%kowi", "a%kiem", "a%ka", "a%kom", "a%ek"]
for suffix in al:
   change[suffix] = 'a%'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
cz = ["cz@w", "czowi", "cza", "czu", "czom", "cz@wna", "cz@wn?", "cz@wny", "cz@wn", "cz@wn!", "czowa", "czowej", "czow?", "czowe", "czowych", "czowym", "czach", "czem", "cze", "czami"]#, "cz"]
for suffix in cz:
   change[suffix] = 'cz'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
#icz = ["iczom", "icz@w", "icz@wna", "iczowi", "icza", "iczowski", "iczach", "icze", "iczami"] #,"icz"]
#for suffix in ski:
#   change[suffix] = 'ski'
ys = ["ysia", "ysiowi", "ysiem", "ysiu", "ysie", "ysi@w", "ysiami", "ysiach", "ysiowa", "ysi@wna", "ysiowej", "ysiow?"]
for suffix in ys:
   change[suffix] = 'y$'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
ny = ["nego", "nemu", "nym", "nej", "n?", "nych", "nymi"]
for suffix in ny:
   change[suffix] = 'ny'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
k = ["kom", "k@wna"]
for suffix in k:
   change[suffix] = 'k'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
l = ["l@wna"]
for suffix in l:
   change[suffix] = 'l'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)
sz = ["sz@wna"]
for suffix in sz:
   change[suffix] = 'sz'
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)

cuts = ["owi", "om", "@w", "owie", "?"]

for suffix in cuts:
   change[suffix] = ''
   length = len(suffix)
   if length not in suflen:
      suflen[length] = []
   suflen[length].append(suffix)

lengths = suflen.keys()
lengths.sort(reverse = True)

def stemmToken(token):
   for lng in lengths:
      if token[-lng:] in suflen[lng]:
         return token[:-lng]+change[token[-lng:]]
   if len(token) >= 6:
      return token[:-1]
